<?php
include_once( 'config.php' );
include_once( 'txwboauth.php' );

$c = new WeiboClient( WB_AKEY , WB_SKEY , $_SESSION['last_key']['oauth_token'] , $_SESSION['last_key']['oauth_token_secret']  );
$aa=$c->pub_abc($_SESSION['last_key']['openid']);
//print_r($aa);
$id = $_SESSION['last_key']['openid'];
$name = $aa['nickname'];
//echo $name;

if(!$id) {
	need_login();
}
if ( $_POST ){
$sns = 'qzone:'.$id;
		$email = $_POST['email'];
	if ( ! Utility::ValidEmail($email, true) ) {
		Session::Set('error', 'Email地址为无效地址');
		redirect( WEB_ROOT . '/account/loginup_qzone.php');
	}
	if($_POST['password']==""){
		Session::Set('error', '请正确输入密码');
		redirect( WEB_ROOT . '/account/loginup_qzone.php');
	}
	$encrypt_pass = ZUser::GenPassword($_POST['password']);
	$update = array(
			'sns' => $sns,			
		);
}
	
		

$au1 = Table::Fetch('user', $email, 'email');
	if($au1['password'] != $encrypt_pass)
		{	
		Session::Set('error', '当前密码不正确');
		Utility::Redirect(WEB_ROOT . '/account/loginup_qzone.php' );}
	$au = Table::Fetch('user', $sns, 'sns');
			if ( $au ) {
				Session::Set('error', '绑定失败，Email已绑定');
	Utility::Redirect(WEB_ROOT . '/account/loginup_qzone.php' );}
			
 if(ZUser::Modify($au1['id'], $update))
	 {
	 	Session::Set('user_id', $au1['id']);
	Utility::Redirect(get_loginpage(WEB_ROOT . '/index.php'));
	 	} 

